﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using models;
using Models;

namespace yuejilalala
{
    //刘振的界面
    public partial class address : System.Web.UI.Page
    {
        AddressManager manager = new AddressManager();
        CartMarager cartMarager = new CartMarager();
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Session["sessid"].ToString());
            if (!IsPostBack)
            {
                if (Session["sess"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                this.Repeater1.DataSource = manager.get(id);
                this.DataBind();
                DropDownList1.DataSource = lianji.lj_shen();
                DropDownList1.DataTextField = "codeName";
                DropDownList1.DataValueField = "code";
                DropDownList1.DataBind();
                userDl();
                if (Session["sessid"] != null)
                {

                    J_MiniCartNum.Text = cartMarager.CartCount((Session["sessid"].ToString())).ProPrice.ToString();//显示出购物车内物品.数量
                }
                }
            }
        }
        public void userDl()
        {
            if (Session["sess"] != null)
            {
                //用户存在则显示出来 并且隐藏注册和登陆显示
                User user = Session["sess"] as User;
                hl_dlm.Text = "用户名:" + user.UName;
                hl_dlm.Visible = true;//显示登陆名控件
                hl_dl.Visible = false;//请登陆隐藏
                hl_zc.Visible = false;//注册隐藏
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Session["sessid"].ToString());
            Address adds = new Address();
            adds.Name = TextBox1.Text;
            adds.Phone =decimal.Parse( TextBox2.Text);
            adds.Addres = DropDownList1.SelectedItem.Text +DropDownList2.SelectedItem + DropDownList3.SelectedItem + TextBox3.Text;
            adds.Rule = 0;
            adds.Userid = id;
            if (manager.add(adds))
            {
                this.Repeater1.DataSource = manager.get(id);
                this.DataBind();
                TextBox1.Text = "";
                TextBox2.Text = "";
                TextBox3.Text = "";
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
        }


        protected void emCommand(object source, RepeaterCommandEventArgs e)
        {

        }

        protected void Repeater1_ItemCommand1(object source, RepeaterCommandEventArgs e)
        {
            int id = int.Parse(Session["sessid"].ToString());
            string nb = e.CommandArgument.ToString();
            if (e.CommandName=="del")
            {
                manager.del(int.Parse(nb));
                this.Repeater1.DataSource = manager.get(id);
                this.DataBind();
            }
            if (e.CommandName== "rule")
            {
                manager.upup();
                manager.uprule(int.Parse(nb));
                this.Repeater1.DataSource = manager.get(id);
                this.DataBind();
             
             
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selshen = DropDownList1.SelectedValue;
            DropDownList2.DataSource = lianji.lj_shi(selshen);
            DropDownList2.DataTextField = "codeName";
            DropDownList2.DataValueField = "code";
            DropDownList2.DataBind();
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selshen = DropDownList2.SelectedValue;
            DropDownList3.DataSource = lianji.lj_qu(selshen);
            DropDownList3.DataTextField = "codeName";
            DropDownList3.DataValueField = "code";
            DropDownList3.DataBind();

        }
    }
}